Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
47 lines (40 loc) · 1.36 KB

3.5.5 - Coroutine/Http2/Client->write.md

File metadata and controls

47 lines (40 loc) · 1.36 KB

Coroutine\Http2\Client->write

向服务器发送更多数据帧,可以多次调用write向同一个stream写入数据帧。

function Coroutine\Http2\Client->write(int $streamId, mixed $data, bool $end = false);
  • $streamId 流编号,由send方法返回
  • $data数据帧的内容,可以为字符串或数组
  • $end 是否关闭流

注意事项

  • 如果要使用write分段发送数据帧,必须在send请求时将$request->pipeline设置为true
  • 当发送endtrue的数据帧之后,流将关闭。之后不能再调用write向此stream发送数据

使用实例

use Swoole\Coroutine as co;

co::create(function () use ($fp)
{
    $cli = new co\Http2\Client('127.0.0.1', 9518);
    $cli->set([ 'timeout' => 1]);
    var_dump($cli->connect());
    
	$req3 = new co\Http2\Request;
	$req3->path = "/index.php";
	$req3->headers = [
		'host' => "localhost",
		"user-agent" => 'Chrome/49.0.2587.3',
		'accept' => 'text/html,application/xhtml+xml,application/xml',
		'accept-encoding' => 'gzip',
	];
	$req3->pipeline = true;
	$req3->method = "POST";
	$streamId = $cli->send($req3);
	$cli->write($streamId, ['int' => rand(1000, 9999)]);
	$cli->write($streamId, ['int' => rand(1000, 9999)]);
	//end stream
	$cli->write($streamId, ['int' => rand(1000, 9999), 'end' => true], true);
	var_dump($cli->recv());
    $cli->close();
});